package embyparse.noobparser;

import java.util.ArrayList;

/**
 * This class stores emby's grammar
 * @author Justin
 *
 */
public class PatternDefinitions {

	/**
	 * Called in order to load all static variables.
	 */
	public static void load(){
	}

	/**
	 * Holds all defined patterns. This is necessary for patterm mathcing.
	 */
	public static final ArrayList<Pattern> ALL_PATTERNS = new ArrayList<Pattern>();

	/**
	 * Holds all patterns used by the matcher. This includes Compound and Grouping patterns.
	 */
	public static final ArrayList<Pattern> MATCHING_PATTERNS = new ArrayList<Pattern>();

	public final static ArrayList<RawPattern> rawpatterns = new ArrayList<RawPattern>();

	public static final Pattern ALL = new Pattern("ALL").add();
	public static final Pattern SYMBOLS = new Pattern("SYMBOLS").add();
	public static final Pattern OP = new Pattern("OP").setSuperPattern("SYMBOLS").add();
	public static final Pattern COMPOP = new Pattern("COMPOP").setSuperPattern("OP").add();
	public static final Pattern INFIXOP = new Pattern("INFIXOP").setSuperPattern("OP").add();
	public static final Pattern PREFIXOP = new Pattern("PREFIXOP").setSuperPattern("OP").add();
	public static final Pattern POSTFIXOP = new Pattern("POSTFIXOP").setSuperPattern("OP").add();
	public static final Pattern EXPR = new Pattern("EXPR").setSuperPattern("ALL").add();
	public static final Pattern LITERAL = new Pattern("LITERAL").setSuperPattern("EXPR").add();
	public static final Pattern VAR = new Pattern("VAR").setSuperPattern("EXPR").add();
	public static final Pattern PAREN = new Pattern("PAREN").setSuperPattern("ALL").add();
	public static final Pattern BLOCK = new Pattern("BLOCK").setSuperPattern("ALL").add();
	public static final Pattern STMT = new Pattern("STMT").setSuperPattern("ALL").add();
	public static final Pattern COMMENT = new Pattern("COMMENT").setSuperPattern("SYMBOLS").add();

	public final static  RawPattern COMMA =   new RawPattern(",").setSuperPattern("COMMENT").add();

	public final static RawPattern ADD =   new RawPattern("+",5).setSuperPattern("INFIXOP").add();
	public final static RawPattern SUB =   new RawPattern("-",5).setSuperPattern("INFIXOP").add();
	public final static RawPattern MUL =   new RawPattern("*",6).setSuperPattern("INFIXOP").add();
	public final static RawPattern DIV =   new RawPattern("/",6).setSuperPattern("INFIXOP").add();
	public final static RawPattern MOD =   new RawPattern("%",6).setSuperPattern("INFIXOP").add();
	public final static RawPattern LESS =   new RawPattern("<",4).setSuperPattern("INFIXOP").add();
	public final static RawPattern GREATER =   new RawPattern(">",4).setSuperPattern("INFIXOP").add();
	public final static RawPattern EQEQ =   new RawPattern("==",3).setSuperPattern("INFIXOP").add();
	public final static RawPattern IS = new RawPattern("is",3).setSuperPattern("INFIXOP").add();
	public final static RawPattern NOTEQ =   new RawPattern("!=",3).setSuperPattern("INFIXOP").add();
	public final static RawPattern GREATEREQ =   new RawPattern(">=",4).setSuperPattern("INFIXOP").add();
	public final static RawPattern LESSEQ =   new RawPattern("<=",4).setSuperPattern("INFIXOP").add();
	public final static RawPattern AND =   new RawPattern("&&",2).setSuperPattern("INFIXOP").add();
	public final static RawPattern OR =   new RawPattern("||",1).setSuperPattern("INFIXOP").add();
	public final static RawPattern PERIOD = new RawPattern(".",8).setSuperPattern("INFIXOP").add();
	public final static RawPattern CARROT =   new RawPattern("^",7).setSuperPattern("INFIXOP").add();
	//public final static RawPattern LAMBDA_ARROW =   new RawPattern("=>",8).setSuperPattern("INFIXOP").add();
	public final static RawPattern ADDCOMP =   new RawPattern("+=").setSuperPattern("COMPOP").add();
	public final static RawPattern SUBCOMP =   new RawPattern("-=").setSuperPattern("COMPOP").add();
	public final static RawPattern MULCOMP =   new RawPattern("*=").setSuperPattern("COMPOP").add();
	public final static RawPattern DIVCOMP =   new RawPattern("/=").setSuperPattern("COMPOP").add();
	public final static RawPattern MODCOMP =   new RawPattern("%=").setSuperPattern("COMPOP").add();
	
	public final static RawPattern NOT = new RawPattern("!",7).setSuperPattern("PREFIXOP").add();

	public final static RawPattern INCRE = new RawPattern("++",8).setSuperPattern("POSTFIXOP").add();
	public final static RawPattern DECRE = new RawPattern("--",8).setSuperPattern("POSTFIXOP").add();

	public final static RawPattern SEMICOLON = new RawPattern(";").setSuperPattern("SYMBOLS").add(); //DO NOT TOUCH THIS!
	public final static RawPattern AT = new RawPattern("@").setSuperPattern("SYMBOLS").add();
	public final static RawPattern COLON =   new RawPattern(":").setSuperPattern("SYMBOLS").add();
	public final static RawPattern OPEN_PAREN = new RawPattern("(",8).setSuperPattern("SYMBOLS").add();
	public final static RawPattern CLOSE_PAREN = new RawPattern(")").setSuperPattern("SYMBOLS").add();
	public final static RawPattern OPEN_BRACK = new RawPattern("{").setSuperPattern("SYMBOLS").add();
	public final static RawPattern CLOSE_BRACK = new RawPattern("}").setSuperPattern("SYMBOLS").add();
	public final static RawPattern OPEN_SQUARE = new RawPattern("[",8).setSuperPattern("SYMBOLS").add();
	public final static RawPattern CLOSE_SQUARE = new RawPattern("]").setSuperPattern("SYMBOLS").add();
	public final static RawPattern OPEN_COMMENT = new RawPattern("/*").setSuperPattern("SYMBOLS").add();
	public final static RawPattern CLOSE_COMMENT = new RawPattern("*/").setSuperPattern("SYMBOLS").add();

	public final static RawPattern ASSIGN =   new RawPattern("=").setSuperPattern("SYMBOLS").add();
	public final static RawPattern IF_STMT =   new RawPattern("if").setSuperPattern("SYMBOLS").add();
	public final static RawPattern ELSE_STMT =   new RawPattern("else").setSuperPattern("SYMBOLS").add();
	public final static RawPattern WHILE_STMT =   new RawPattern("while").setSuperPattern("SYMBOLS").add();
	public final static RawPattern FOR =   new RawPattern("for").setSuperPattern("SYMBOLS").add();
	public final static RawPattern DEF_STMT =   new RawPattern("fn").setSuperPattern("SYMBOLS").add();
	public final static RawPattern RET = new RawPattern("return").setSuperPattern("SYMBOLS").add();
	public final static RawPattern TRY =   new RawPattern("try").setSuperPattern("SYMBOLS").add();
	public final static RawPattern CATCH =   new RawPattern("catch").setSuperPattern("SYMBOLS").add();
	public final static RawPattern THROW =   new RawPattern("throw").setSuperPattern("SYMBOLS").add();
	public final static RawPattern BREAK =   new RawPattern("break").setSuperPattern("SYMBOLS").add();
	public final static RawPattern PROP_STMT =   new RawPattern("property").setSuperPattern("SYMBOLS").add();
	public final static RawPattern CLASS =   new RawPattern("class").setSuperPattern("SYMBOLS").add();
	public final static RawPattern NEW = new RawPattern("new").setSuperPattern("SYMBOLS").add();

	public final static CompoundPattern INDEX=  (CompoundPattern) new CompoundPattern(8,"INDEX","[","EXPR","]").setSuperPattern("SYMBOLS").add();
	public final static CompoundPattern SLICE=  (CompoundPattern) new CompoundPattern("SLICE","[","EXPR",":","EXPR","]").setSuperPattern("POSTFIXOP").add();

	//EXPRESSIONS
	public final static Pattern CALL = new Pattern("CALL").setSuperPattern("EXPR").add();
	public final static Pattern INFIXCALL = new Pattern("INFIXCALL").setSuperPattern("CALL").add();
	public final static Pattern PREFIXCALL = new Pattern("PREFIXCALL").setSuperPattern("CALL").add();
	public final static Pattern POSTFIXCALL = new Pattern("POSTFIXCALL").setSuperPattern("CALL").add();
	public final static CompoundPattern INDEXCALL=  (CompoundPattern) new CompoundPattern(8,"INDEXCALL","EXPR","INDEX").setSuperPattern("VAR").add();
	//public final static CompoundPattern NEW_OP =  (CompoundPattern) new CompoundPattern(8,"NEW","new","FNCALL").setSuperPattern("EXPR").add();
	public final static CompoundPattern FNCALL2 = (CompoundPattern) new CompoundPattern(8,"FNCALL","EXPR","PAREN").setSuperPattern("CALL").add();
	public final static CompoundPattern LAMBDA1 = (CompoundPattern) new CompoundPattern("LAMBDA","fn","PAREN","EXPR").setSuperPattern("EXPR").add();
	public final static CompoundPattern LAMBDA2 = (CompoundPattern) new CompoundPattern("LAMBDA","fn","PAREN","BLOCK").setSuperPattern("EXPR").add();
	
	//INFIX CALLS
	public final static CompoundPattern INFX_ADD =  (CompoundPattern) new CompoundPattern(5,"INFX_ADD","EXPR","+","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_SUB =  (CompoundPattern) new CompoundPattern(5,"INFX_SUB","EXPR","-","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_MUL =  (CompoundPattern) new CompoundPattern(6,"INFX_MUL","EXPR","*","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_DIV =  (CompoundPattern) new CompoundPattern(6,"INFX_DIV","EXPR","/","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_MOD =  (CompoundPattern) new CompoundPattern(6,"INFX_MOD","EXPR","%","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_GREAT =  (CompoundPattern) new CompoundPattern(4,"INFX_GREAT","EXPR",">","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_LESS=  (CompoundPattern) new CompoundPattern(4,"INFX_LESS","EXPR","<","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_GREQ =  (CompoundPattern) new CompoundPattern(4,"INFX_GREQ","EXPR",">=","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_LEEQ =  (CompoundPattern) new CompoundPattern(4,"INFX_LEEQ","EXPR","<=","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_EQEQ =  (CompoundPattern) new CompoundPattern(3,"INFX_EQEQ","EXPR","==","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_IS =  (CompoundPattern) new CompoundPattern(3,"INFX_IS","EXPR","is","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_NEQ =  (CompoundPattern) new CompoundPattern(3,"INFX_NEQ","EXPR","!=","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_AND =  (CompoundPattern) new CompoundPattern(2,"INFX_AND","EXPR","&&","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_OR =  (CompoundPattern) new CompoundPattern(1,"INFX_OR","EXPR","||","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_CARROT =  (CompoundPattern) new CompoundPattern(7,"INFX_CARROT","EXPR","^","EXPR").setSuperPattern("INFIXCALL").add();
	public final static CompoundPattern INFX_DOT =  (CompoundPattern) new CompoundPattern(8,"DOTCALL","EXPR",".","EXPR").setSuperPattern("VAR").add();
	//PREFIX CALLS
	public final static CompoundPattern PRFX_NOT =  (CompoundPattern) new CompoundPattern(7,"PRFX_NOT","!","EXPR").setSuperPattern("PREFIXCALL").add();
	public final static CompoundPattern PRFX_NEG =  (CompoundPattern) new CompoundPattern(5,"PRFX_NEG","-","EXPR").setSuperPattern("PREFIXCALL").add();
	//POSTFIX CALLS
	public final static CompoundPattern POFX_INCR =  (CompoundPattern) new CompoundPattern(8,"POFX_INCR","EXPR","++").setSuperPattern("POSTFIXCALL").add();
	public final static CompoundPattern POFX_DECR =  (CompoundPattern) new CompoundPattern(8,"POFX_DECR","EXPR","--").setSuperPattern("POSTFIXCALL").add();
	public final static CompoundPattern POFX_SLICE =  (CompoundPattern) new CompoundPattern(8,"POFX_SLICE","EXPR","SLICE").setSuperPattern("POSTFIXCALL").add();

	//STATEMENTS
	//public final static CompoundPattern DOTASSIGN =  (CompoundPattern) new CompoundPattern("ASSIGN_STMT","DOTCALL","=","EXPR").setSuperPattern("STMT").add();
	public final static CompoundPattern ASSIGN1 =  (CompoundPattern) new CompoundPattern("ASSIGN_STMT","VAR","=","EXPR").setSuperPattern("STMT").add();
	public final static CompoundPattern COMPOUND_ASSIGN=  (CompoundPattern) new CompoundPattern("COMPASSIGN_STMT","VAR","COMPOP","EXPR").setSuperPattern("ASSIGN_STMT").add();
	//public final static CompoundPattern ASSIGN2 =  (CompoundPattern) new CompoundPattern("ASSIGN_STMT","VAR","=","PAREN").setSuperPattern("STMT").add();
	public final static CompoundPattern IF1 =  (CompoundPattern) new CompoundPattern("IF_STMT","if","EXPR","BLOCK").setSuperPattern("STMT").add();
	public final static CompoundPattern IF2 =  (CompoundPattern) new CompoundPattern("IF_STMT","if","EXPR","ALL").setSuperPattern("STMT").add();
	public final static CompoundPattern ELSE_CLAUSE1 =  (CompoundPattern) new CompoundPattern("ELSE_STMT","else","BLOCK").setSuperPattern("STMT").add();
	public final static CompoundPattern ELSE_CLAUSE2 =  (CompoundPattern) new CompoundPattern("ELSE_STMT","else","ALL").setSuperPattern("STMT").add();
	public final static CompoundPattern IFELSE =  (CompoundPattern) new CompoundPattern("IFELSE","IF_STMT","ELSE_STMT").setSuperPattern("STMT").add();

	public final static CompoundPattern WHILE =  (CompoundPattern) new CompoundPattern("WHILE_STMT","while","EXPR","BLOCK").setSuperPattern("STMT").add();
	public final static CompoundPattern FOR_STMT  =  (CompoundPattern) new CompoundPattern("FOR_STMT","for","PAREN","BLOCK").setSuperPattern("STMT").add();
	//public final static CompoundPattern RET1 =  (CompoundPattern) new CompoundPattern("RET_STMT","return","PAREN").setSuperPattern("STMT").add();
	public final static CompoundPattern RET2 =  (CompoundPattern) new CompoundPattern("RET_STMT","return","EXPR").setSuperPattern("STMT").add();
	public final static CompoundPattern DEF = (CompoundPattern) new CompoundPattern("DEF_STMT","DEF_INCOMPLETE","BLOCK").setSuperPattern("STMT").add();
	public final static CompoundPattern DEF_INCOMPLETE = (CompoundPattern) new CompoundPattern(9,"DEF_INCOMPLETE","fn","FNCALL").setSuperPattern("SYMBOLS").add();
	public final static CompoundPattern TRY_CLAUSE =  (CompoundPattern) new CompoundPattern("TRY_CLAUSE","try","BLOCK").setSuperPattern("SYMBOLS").add();
	public final static CompoundPattern CATCH_CLAUSE =  (CompoundPattern) new CompoundPattern("CATCH_CLAUSE","catch","PAREN","BLOCK").setSuperPattern("SYMBOLS").add();
	public final static CompoundPattern TRYCATCH =  (CompoundPattern) new CompoundPattern("TRYCATCH","TRY_CLAUSE","CATCH_CLAUSE").setSuperPattern("STMT").add();
	public final static CompoundPattern THROW_STMT=  (CompoundPattern) new CompoundPattern("THROW_STMT","throw","EXPR").setSuperPattern("STMT").add();
	//public final static CompoundPattern GENERIC_BLOCK = (CompoundPattern) new CompoundPattern("GEN_BLOCK","@","FNCALL","BLOCK").setSuperPattern("EXPR").add();
	public final static CompoundPattern GENERIC_BLOCK2 = (CompoundPattern) new CompoundPattern("GEN_BLOCK","@","EXPR","BLOCK").setSuperPattern("EXPR").add();
	
	public static final GroupingPattern MULTILINE_COMMENT = (GroupingPattern) new GroupingPattern(0,"MULTILINE_COMMENT",OPEN_COMMENT,CLOSE_COMMENT).setSuperPattern("COMMENT").add();
	public static final GroupingPattern PAREN_GRP = (GroupingPattern) new GroupingPattern(0,"PAREN",OPEN_PAREN,CLOSE_PAREN).setSuperPattern("EXPR").add(); //CARE: Used for lookahead in CompoundPattern
	public static final GroupingPattern BLOCK_GRP = (GroupingPattern) new GroupingPattern(0,"BLOCK",OPEN_BRACK,CLOSE_BRACK).setSuperPattern("EXPR").add();
	public static final GroupingPattern LIST_LITERAL = (GroupingPattern) new GroupingPattern(0,"LIST_EXPRESSION",OPEN_SQUARE,CLOSE_SQUARE).setSuperPattern("EXPR").add();

}
